package com.iss.card.db;

import android.content.ContentValues;
import android.database.Cursor;
import android.util.Log;

import com.iss.card.db.CardContract.Accounts;
import com.iss.card.db.CardContract.Stores;
import com.iss.card.view.account.CardAccountModel;
import com.iss.card.view.store.StoreModel;

public class DBHelper {
	
	static private final String TAG = DBHelper.class.getCanonicalName();
	
	public static final String[] ACCOUNT_PROJECTION = new String[] {
		Accounts._ID, // 0
		Accounts.ACCOUNT, // 1
		Accounts.PASSWORD, // 2
		Accounts.DELETE_SIGN, // 3
	};
	
	protected static final int ACCOUNT_INDEX_ID = 0;
	protected static final int ACCOUNT_INDEX_ACCOUNT = 1;
	protected static final int ACCOUNT_INDEX_PASSWORD = 2;
	protected static final int ACCOUNT_INDEX_DELETE_SIGN = 3;
	
	public static final String[] STORE_PROJECTION = new String[] {
		Stores.STORE_ID, // 0
	};
	
	protected static final int STORE_STORE_ID = 0;
	
	public static final String[] STORE_COLLENT_PROJECTION = new String[]{
		Stores._ID, // 0
		Stores.ACCOUNT_ID, // 1
    	Stores.STORE_ID, // 2
    	Stores.STORE_NAME, // 3
    	Stores.USER_ID, // 4
    	Stores.STORE_MOBILE, // 5
    	Stores.STORE_PROVINCE, // 6
    	Stores.STORE_CITY, // 7
    	Stores.STORE_DISTRICT, // 8
    	Stores.STORE_ADDRESS, // 9
    	Stores.STORE_VIP_NUM, // 10
    	Stores.REQUEST_DATE, // 11
    	Stores.CREAT_DATE, // 12
    	Stores.UPDATE_BY, // 13
    	Stores.UPDATE_DATE, // 14
    	Stores.STATUS_FLAG, // 15
    	Stores.USER_NAME, // 16
    	Stores.PROVINCE_NAME, // 17
    	Stores.CITY_NAME, // 18
    	Stores.STORE_TYPE, // 19
    	Stores.STORE_CATE, // 20
    	Stores.JING_DU, // 21
    	Stores.WEI_DU, // 22
    	Stores.FIRST_PAGE, // 23
    	Stores.APPROVE_DATE, // 24
    	Stores.CREAT_BY, // 25
    	Stores.APPROVER, // 26
    	Stores.USER_MOBILE, // 27
    	Stores.USER_EMAIL, // 28
    	Stores.SECOND_PAGE, // 29
    	Stores.AD_URL, // 30
    	Stores.PIC_HEIGHT, // 31
    	Stores.PIC_WIDTH, // 32
    	Stores.COUNT, // 33
    	Stores.PIC_URL, // 34
    	Stores.DELETE_SGIN, // 35
	};
	
	protected static final int ACCOUNT_INDEX_STORES_ID = 0;
	protected static final int ACCOUNT_INDEX_ACCOUNT_ID = 1;
	protected static final int ACCOUNT_INDEX_STORE_ID = 2;
	protected static final int ACCOUNT_INDEX_STORE_NAME = 3;
	protected static final int ACCOUNT_INDEX_USER_ID = 4;
	protected static final int ACCOUNT_INDEX_STORE_MOBILE = 5;
	protected static final int ACCOUNT_INDEX_STORE_PROVINCE = 6;
	protected static final int ACCOUNT_INDEX_STORE_CITY = 7;
	protected static final int ACCOUNT_INDEX_STORE_DISTRICT = 8; 
	protected static final int ACCOUNT_INDEX_STORE_ADDRESS = 9; 
	protected static final int ACCOUNT_INDEX_STORE_VIP_NUM = 10; 
	protected static final int ACCOUNT_INDEX_REQUEST_DATE = 11; 
	protected static final int ACCOUNT_INDEX_CREAT_DATE = 12; 
	protected static final int ACCOUNT_INDEX_UPDATE_BY = 13; 
	protected static final int ACCOUNT_INDEX_UPDATE_DATE = 14; 
	protected static final int ACCOUNT_INDEX_STATUS_FLAG = 15; 
	protected static final int ACCOUNT_INDEX_USER_NAME = 16; 
	protected static final int ACCOUNT_INDEX_PROVINCE_NAME = 17; 
	protected static final int ACCOUNT_INDEX_CITY_NAME = 18; 
	protected static final int ACCOUNT_INDEX_STORE_TYPE = 19;
	protected static final int ACCOUNT_INDEX_STORE_CATE = 20; 
	protected static final int ACCOUNT_INDEX_JING_DU = 21; 
	protected static final int ACCOUNT_INDEX_WEI_DU = 22; 
	protected static final int ACCOUNT_INDEX_FIRST_PAGE = 23; 
	protected static final int ACCOUNT_INDEX_APPROVE_DATE = 24; 
	protected static final int ACCOUNT_INDEX_CREAT_BY = 25; 
	protected static final int ACCOUNT_INDEX_APPROVER = 26; 
	protected static final int ACCOUNT_INDEX_USER_MOBILE = 27; 
	protected static final int ACCOUNT_INDEX_USER_EMAIL = 28; 
	protected static final int ACCOUNT_INDEX_SECOND_PAGE = 29; 
	protected static final int ACCOUNT_INDEX_AD_URL = 30; 
	protected static final int ACCOUNT_INDEX_PIC_HEIGHT = 31;
	protected static final int ACCOUNT_INDEX_PIC_WIDTH = 32; 
	protected static final int ACCOUNT_INDEX_COUNT = 33; 
	protected static final int ACCOUNT_INDEX_PIC_URL = 34; 
	protected static final int ACCOUNT_INDEX_DELETE_SGIN = 35; 
	
	
	
    public static void setCardAccountModelFromCursor(CardAccountModel model, Cursor cursor) {
        if (model == null || cursor == null || cursor.getCount() != 1) {
            Log.wtf(TAG, "Attempted to build non-existent model or from an incorrect query.");
            return;
        }
        
        cursor.moveToFirst();
        
        model._id = cursor.getInt(ACCOUNT_INDEX_ID);
        model.account = cursor.getString(ACCOUNT_INDEX_ACCOUNT);
        model.password = cursor.getString(ACCOUNT_INDEX_PASSWORD);
        model.deleteSign = cursor.getString(ACCOUNT_INDEX_DELETE_SIGN);
    }
    
    public static void setStoreModelFromCursor(StoreModel model, Cursor cursor) {
        if (model == null || cursor == null) {
            Log.wtf(TAG, "Attempted to build non-existent model or from an incorrect query.");
            return;
        }
        
//        model.storeID = cursor.getString(STORE_STORE_ID);
    }
    
    public static void setContentValuesForStore(ContentValues values, StoreModel info){
        if (values == null || info == null) {
            Log.wtf(TAG, "Set content values for store fail.");
            return;
        }
        
//        values.put(Stores.ACCOUNT_ID, info.accountId);
//    	values.put(Stores.STORE_ID, info.storeID);
//    	values.put(Stores.STORE_NAME, info.storeName);
//    	values.put(Stores.USER_ID, info.userID);
//    	values.put(Stores.STORE_MOBILE, info.storeMobile);
//    	values.put(Stores.STORE_PROVINCE, info.storeProvince);
//    	values.put(Stores.STORE_CITY, info.storeCity);
//    	values.put(Stores.STORE_ADDRESS, info.storeAddress);
//    	values.put(Stores.USER_NAME, info.userName);
//    	values.put(Stores.PROVINCE_NAME, info.provinceName);
//    	values.put(Stores.CITY_NAME, info.cityName);
//    	values.put(Stores.STORE_TYPE, info.storeType);
//    	values.put(Stores.JING_DU, info.jingdu);
//    	values.put(Stores.WEI_DU, info.weidu);
//    	values.put(Stores.PIC_URL, info.picUrl);
//    	values.put(Stores.STATUS_FLAG, info.statusFlag);
//    	values.put(Stores.FIRST_PAGE, info.isFirstPage);
//    	values.put(Stores.STORE_CATE, info.storeCate);
//    	values.put(Stores.PIC_HEIGHT, info.picHeight);
//    	values.put(Stores.PIC_WIDTH, info.picWidth);
    	values.put(Stores.DELETE_SGIN, "0");
    }
    
    public static void setStoreCollentInfoFromDB(StoreModel info, Cursor cursor){

//    	info._id = cursor.getInt(ACCOUNT_INDEX_STORES_ID);
//    	info.accountId = cursor.getLong(ACCOUNT_INDEX_ACCOUNT_ID);
//    	info.storeID = cursor.getString(ACCOUNT_INDEX_STORE_ID);
//    	info.storeName = cursor.getString(ACCOUNT_INDEX_STORE_NAME);
//    	info.userID = cursor.getString(ACCOUNT_INDEX_USER_ID);
//    	info.storeMobile = cursor.getString(ACCOUNT_INDEX_STORE_MOBILE);
//    	info.storeProvince = cursor.getString(ACCOUNT_INDEX_STORE_PROVINCE);
//    	info.storeCity = cursor.getString(ACCOUNT_INDEX_STORE_CITY);
//    	info.storeAddress = cursor.getString(ACCOUNT_INDEX_STORE_ADDRESS);
//    	info.userName = cursor.getString(ACCOUNT_INDEX_USER_NAME);
//    	info.provinceName = cursor.getString(ACCOUNT_INDEX_PROVINCE_NAME);
//    	info.cityName = cursor.getString(ACCOUNT_INDEX_CITY_NAME); 
//    	info.storeType = cursor.getString(ACCOUNT_INDEX_STORE_TYPE);
//    	info.jingdu = cursor.getString(ACCOUNT_INDEX_JING_DU); 
//    	info.weidu = cursor.getString(ACCOUNT_INDEX_WEI_DU);
//    	info.picUrl = cursor.getString(ACCOUNT_INDEX_PIC_URL);
//    	info.statusFlag = cursor.getString(ACCOUNT_INDEX_STATUS_FLAG);
//    	info.isFirstPage = cursor.getString(ACCOUNT_INDEX_FIRST_PAGE);
//    	info.storeCate = cursor.getString(ACCOUNT_INDEX_STORE_CATE);
//    	info.picHeight = cursor.getString(ACCOUNT_INDEX_PIC_HEIGHT);
//    	info.picWidth = cursor.getString(ACCOUNT_INDEX_PIC_WIDTH);
//    	info.deleteSign = cursor.getString(ACCOUNT_INDEX_DELETE_SGIN);
    }

}
